<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="pro_list fr"  >
   <div class="title"  >
   	 <span class="titletxt">您现在的位置：</span>
     <ul> 
       <li class="root">会员中心</li>        
       <li>供货商管理</li>  
       <li>库存查询</li>            
     </ul>
   </div>
  <c:if test="${not empty ret }">
   	<c:if test="${ret.code ne '200'}">
   		<script type="text/javascript">alertError('${ret.result}');</script>
   		<div id=messager class="messager" >
	         <div class="contentmsg">
	             <h5>提示信息～！</h5>
	             <ul>
	               <li>${ret.result}</li>
	             </ul>
	        </div>
	     <div class="closer" onClick="showHideLayer('messager');" title="关闭"></div>
	    </div>
   	</c:if>
   </c:if>
<br/>
<div  class="easyui-panel" title="库存查询"  style="">
    <div data-options="region:'north',title:'',split:true" style="height:40px;background-color:#e4e4e4;">
		<form action="" id="searchForm" name="searchForm">
    	<table>
    		<tr>
    			<td class="screen-n"><span>商品编号</span></td>
				<td class="screen-n">
					<input type="text" id="spbh" class="screen-input" >
				</td>
				<td class="screen-n"><span>商品名称</span></td>
				<td class="screen-n">
					<input type="text" id="spmch" class="screen-input">
				</td>
				<td class="screen-n">
					<a class="easyui-linkbutton l-btn l-btn-small" onclick="initStock()"><span class="l-btn-left"><span class="l-btn-text">查询</span></span></a>&nbsp;
					<a class="easyui-linkbutton l-btn l-btn-small" onclick="pms.resetForm('searchForm')" ><span class="l-btn-left"><span class="l-btn-text">重置</span></span></a>&nbsp;
					<a class="easyui-linkbutton l-btn l-btn-small" onclick="downloadStock()" group="" id=""><span class="l-btn-left"><span class="l-btn-text">导出到excel</span></span></a>&nbsp;
				</td>
			</tr>
			</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height:431px">
		<table id="tableGrid" ></table>
	</div>
	
</div>
</div>
<script>
var productsTable;
$(function(){
	initStock();
});

function initStock(){
   	productsTable = $('#tableGrid').pDataGrid({
		 columns:[[
	          	  {field:'spmch',title:'商品名称',align:'center',sortable:true},
	          	  {field:'shpgg',title:'商品规格',align:'center',sortable:true},
	          	  {field:'dw',title:'包装单位',align:'center',sortable:true},
	          	  {field:'shengccj',title:'生产厂家',align:'center',sortable:true},
	          	  {field:'lshpj',title:'国零价',align:'center',sortable:true},
	          	  {field:'pihao2',title:'&nbsp;批&nbsp;号',align:'center',sortable:true},
	          	  {field:'shl',title:'&nbsp;数量',align:'center',sortable:true},
	           	  {field:'sxrq',title:'有效日期',align:'center',sortable:true}
		          ]],
		    url:'<c:url value="/xcB2B/searchXcPageStock.s"/>',  
		    pagination:true,
		    pageSize:50,
 		    queryParams:{
 		    	"spbh":$("#spbh").val(),
 		    	"spmch":$("#spmch").val()
		    },
			completeCallback:function(data){
				if(data.code == "100"){
					alertError(data.result);
				}else{
					 
				}
			}
	}); 
}
var canSub = true;
function downloadStock(){
	if(canSub){
		$.ajax({
			url : '<c:url value="/xcB2B/searchXcPageStockExcel.s"/>',
			pagination : false,
			type : "POST",
			dataType : "json",
			data:{
 		    	"spbh":$("#spbh").val(),
 		    	"spmch":$("#spmch").val()
		    },
			beforeSend:function(){
				canSub = false;
				layer.alert("资料正在打包整理中,耗时较长,请耐心等待...", {icon: 6});
			},
			complete:function(){
				canSub = true;
			},
			success : function(data) {
				if (data.code == "100") {
					layer.msg("装载要下载的数据出错啦,错误代码：" + data.result);
				} else if (data.code == "101") {
					layer.msg(data.result);
				} else {
					location.href = '<c:url value="/util/load.s?"/>fileName='
							+ data.data.outPath + '&title=' + data.data.title;
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				layer.msg(" --下载出错啦 请联系管理员!");
			}
		});
	}else{
		layer.alert("资料正在打包整理中,请耐心等待...");
	}
}
</script>